﻿package modular {
	import flash.geom.Point;				

	/**
	 * @author mich
	 */
	public class ModuleInfo {

		private var xml:XML;
		private var loader:ModuleSetLoader;

		public function ModuleInfo( xml:XML ) {
			this.xml = xml;
		}

		public function equals( info:ModuleInfo ):Boolean {
			return id == info.id && className == info.className;
		}
		
		public function getParams(  ):XML {
			if( xml.hasOwnProperty( "params" ) ) {
				return xml.params[0];
			} else {
				throw new Error( "cant access params node in: " + this );
			}
		}

		public function get className():String {
			return xml.@["class"];
		}

		public function get libraryPath():String {
			return xml.library.@path;
		}

		public function get id():String {
			return xml.@id;
		}

		public function get position():Point {

			var x:Number = ( xml.position.hasOwnProperty( "@x" ) ) ? Number( xml.position.@x ) : NaN;
			var y:Number = ( xml.position.hasOwnProperty( "@y" ) ) ? Number( xml.position.@y ) : NaN;
			return new Point(x, y);
		}
		
		public function get width():Number {
			return ( xml.size.hasOwnProperty( "@width" ) ) ? Number( xml.size.@width ) : NaN;
		}
		
		public function get height():Number {
			return ( xml.size.hasOwnProperty( "@height" ) ) ? Number( xml.size.@height ) : NaN;
		}
		
		public function get parentLoader():ModuleSetLoader {
			return loader;
		}
		
		public function set parentLoader( msl:ModuleSetLoader ):void {
			loader = msl;
		}

		public function get rawXML():XML {
			return xml;
		}

		public function toString():String {
			return "ModuleInfo: " + xml.toString();
		}
		
		public function destroy():void {
			xml = null;
			loader = null;
		}
	}
}
